package com.bosssoft.trainee.nontax.service.impl;

import com.bosssoft.trainee.nontax.dao.UserRoleDao;
import com.bosssoft.trainee.nontax.service.UserRoleService;
import com.bosssoft.trainee.nontax.entity.po.UserRole;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: (UserRole)表服务实现类
 * @author makejava
 * @since 2022-06-12 10:16:46
 */
@Service("userRoleService")
public class UserRoleServiceImpl implements UserRoleService {
    @Resource
    private UserRoleDao userRoleDao;

    /**
     * @Description: 分页查询
     * @param userRole 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<UserRole> queryByPage(UserRole userRole, PageRequest pageRequest) {
        long total = this.userRoleDao.count(userRole);
        return new PageImpl<>(this.userRoleDao.queryAllByLimit(userRole, pageRequest), pageRequest, total);
    }

    /**
     * @Description: 新增数据
     * @param userRole 实例对象
     * @return 实例对象
     */
    @Override
    public UserRole insert(UserRole userRole) {
        this.userRoleDao.insert(userRole);
        return userRole;
    }

    /**
     * @Description: 修改数据
     * @param userRole 实例对象
     * @return 实例对象
     */
    @Override
    public int update(UserRole userRole) {
        return this.userRoleDao.update(userRole);
    }

    /**
     * @Description: 插入或者更新
     * @param userRole userRole
     * @return: int 成功操作行数
     * @Author: Luo WenLong
     * @Date: 2022/6/26 13:28
     */
    @Override
    public int insertOrUpdate(UserRole userRole) {
        List<UserRole> userRoles = new ArrayList<>();
        userRoles.add(userRole);
        return this.userRoleDao.insertOrUpdateBatch(userRoles);
    }

}
